package com.iwhalecloud.citybrain.flow.platform.manager.application.common.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Enum - 流程实例可进行的操作
 *
 * @author lilh
 * @date 2019-07-26 10:39
 */
public enum ProcessInstanceActionEnum {

    //挂起，解挂，撤单， 终止


    /**
     * 挂起
     */
    PAUSE("PAUSE", "挂起"),

    UNPAUSE("UNPAUSE", "解挂"),

    RECALL("RECALL", "撤单"),

    END("END", "终止"),

    UPGRADE("UPGRADE","迁移至最新版本");

    private String code;

    private String desc;

    private static Map<String, String> codeToDesc;

    static {
        codeToDesc = Arrays.stream(values()).collect(Collectors.toMap(ProcessInstanceActionEnum::getCode, ProcessInstanceActionEnum::getDesc));
    }

    ProcessInstanceActionEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static String getDesc(String code) {
        return codeToDesc.get(code);
    }

    public static ProcessInstanceActionEnum fromCode(String code) {
        for (ProcessInstanceActionEnum handleEnum : ProcessInstanceActionEnum.values()) {
            if (handleEnum.code.equals(code)) {
                return handleEnum;
            }
        }
        return null;
    }
}
